package com.du.managerback.exception;

import com.du.managerback.utils.BaseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局异常
@ControllerAdvice("com.du.managerback.controller")
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody //给前端返回一个Json数据格式的数据
    public BaseResult error(Exception e) {
        e.printStackTrace();
        return BaseResult.error();
    }
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public BaseResult customError(CustomException e){
        e.printStackTrace();
        return BaseResult.error(e.getCode(),e.getMsg());

    }
}